﻿using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.Sqlite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KorbeRTR.Utility
{
    public class UserDBHelper
    {
        public static string ConnectString = "Data Source=Database/UserDB.db";

        public static DataTable ExecuteTable(string cmdText, params SqliteParameter[] parameters)
        {
            using (var conn = new SqliteConnection(ConnectString))
            {
                conn.Open();
                var cmd = new SqliteCommand(cmdText, conn);
                cmd.Parameters.AddRange(parameters);

                var dt = new DataTable();
                using (var reader = cmd.ExecuteReader())
                {
                    dt.Load(reader);
                }

                return dt;
            }
        }

        public static int ExecuteNonQuery(string cmdText, params SqliteParameter[] parameters)
        {
            using (var conn = new SqliteConnection(ConnectString))
            {
                conn.Open();
                var cmd = new SqliteCommand(cmdText, conn);
                cmd.Parameters.AddRange(parameters);
                return cmd.ExecuteNonQuery();
            }
        }

    }
}
